package com.api.gbhg.zengping.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSetTrans;

import java.util.Map;

/**
 * @program: gbhg-oa
 * @author: Mr.zeng
 * @create: 2020-12-30 11:27
 *
 * 离退休人员
 **/
public class RetiredPeopleDao implements Dao{
    public static final Logger LOGGER = LoggerFactory.getLogger("gbhg");

    @Override
    public RecordSetTrans getSBInfo(String lcStatus,Integer pageNum,Integer pageSize,String requestId){
        RecordSetTrans rst=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql="select lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,yszje from uf_jingfei_version v,uf_txrygzjtbtbb t,uf_txrygzjtbtbb_dt1\n" +
                "where t.requestId=v.lcjlsqjlid AND mainid=t.id";
        try {
            sb.append(sql);
            String group=" group by lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,yszje ";
            sb=PropertyManagementCostDao.limitSize(rst,sb,lcStatus,pageNum,pageSize,group,requestId);
            LOGGER.info("===========离退休人员津贴核批列表数据查询==================="+sb.toString());
            rst.executeSql(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rst.rollback();
        }
        return rst;
    }

    public RecordSetTrans getSBInfo(String requestId){
        RecordSetTrans rst=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql="select lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,yszje from uf_jingfei_version v,uf_txrygzjtbtbb t,uf_txrygzjtbtbb_dt1\n" +
                "where t.requestId=v.lcjlsqjlid AND mainid=t.id";
        try {
            sb.append(sql);
            String group=" group by lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,yszje ";
            sb=PropertyManagementCostDao.limitSize(sb,group,requestId);
            LOGGER.info("离退休人员津贴核批列表数据查询:------------------->"+sb.toString());
            rst.executeSql(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
            rst.rollback();
        }
        return rst;
    }
    /**
     * 海关离退休核批列表查询条数   uf_wygljfbb
     * @param lcztz
     * @return
     */
    @Override
    public RecordSetTrans getSBInfoCount(String lcztz,String tableName,String requestId){
        RecordSetTrans rts=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql="select count(1)num from (select lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,sum(yszje)yszje from uf_jingfei_version v,uf_txrygzjtbtbb t,uf_txrygzjtbtbb_dt1\n" +
                "where t.requestId=v.lcjlsqjlid AND mainid=t.id";

        sb.append(sql);
        try {
            if("3".equals(lcztz)){
                sb.append(" AND lcztz="+lcztz +" and t.requestId IN("+requestId+")");
            }else {
                sb.append(" AND lcztz<> 3 and t.requestId IN("+requestId+")");
            }
            sb.append(" group by lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr )t");
            LOGGER.info("===========海关离退休核批列表查询条数==================="+sb.toString());
            rts.executeQuery(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }
    public RecordSetTrans getSBInfoCount(String tableName,String requestId){
        RecordSetTrans rts=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql="select count(1)num from (select lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr,sum(yszje)yszje from uf_jingfei_version v,uf_txrygzjtbtbb t,uf_txrygzjtbtbb_dt1\n" +
                "where t.requestId=v.lcjlsqjlid AND mainid=t.id";

        sb.append(sql);
        try {
                sb.append(" and t.requestId IN("+requestId+")");
            sb.append(" group by lcjlsqjlid,t.id,xmmin,sbdw,sbks,fzr )t");
            LOGGER.info("海关离退休核批列表查询条数:------------->"+sb.toString());
            rts.executeQuery(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }

    /**
     * update 添加填入的核批预算来源
     * @param param
     * @return
     */
    public boolean modifyRetiredPeople(Map<String,Object> param){
        RecordSetTrans rst=new RecordSetTrans();
        rst.setAutoCommit(false);
        String sql="update "+param.get("fromTable")+" set zyczbkze=?,sjbzsrhpje=?,sydwjysrhpje=?,dfczxmzcze=?," +
                "dfczjbzchpje=?,zyzyzfhpje=?,bjhxbkhpje=?,lxsrhpje=?,xjdwsjsrhpje=? where requestId=?";
        try {
            /*中央财政拨款总额  上级补助收入核批金额  事业单位经营收入核批金额  地方财政项目支出总额  地方财政基本支出核批金额  中央转移支付核批金额
            本级横向拨款核批金额 利息收入核批金额 下级单位上缴收入核批金额  事业单位经营收入核批金额*/
            rst.executeUpdate(sql,
                    param.get("zyczbkze"),
                    param.get("sjbzsrhpje"),
                    param.get("sydwjysrhpje"),
                    param.get("dfczxmzcze"),
                    param.get("dfczjbzchpje"),
                    param.get("zyzyzfhpje"),
                    param.get("bjhxbkhpje"),
                    param.get("lxsrhpje"),
                    param.get("xjdwsjsrhpje"),
                    param.get("requestId")
                    );
        } catch (Exception e) {
            e.printStackTrace();
            rst.rollback();
            return false;
        }
        rst.commit();
        return true;
    }

}
